package cn.edu.zut.soft.student.controller.teacher;

import cn.edu.zut.soft.student.bean.ResultBean;
import cn.edu.zut.soft.student.model.*;
import cn.edu.zut.soft.student.service.course.SelectCourseStudentsBo;
import cn.edu.zut.soft.student.service.notice.NoticeBo;
import cn.edu.zut.soft.student.service.notice.vo.NoticeQuery;
import cn.edu.zut.soft.student.service.student.StudentBo;
import cn.edu.zut.soft.student.service.student.StudentSelectCoursesBo;
import cn.edu.zut.soft.student.service.teacher.TeacherBo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author ChrisPhantom
 * @CreatDate 2021/02/24 19:42
 */

@RestController
@RequestMapping("/teacher/api")
public class TeaController {
    @Autowired
    private NoticeBo noticeBo;
    @Autowired
    private TeacherBo teacherBo;
    @Autowired
    private StudentBo studentBo;
    @Autowired
    private SelectCourseStudentsBo scsb;
    @Autowired
    private StudentSelectCoursesBo sscb;

    @PostMapping("/{teacherid}")
    public ResultBean<Integer> updatePassword(@PathVariable("teacherid") String teacherid, String newpassword) {
        return new ResultBean<>(teacherBo.resetPassword(teacherid, newpassword));
    }

    @PutMapping("/score")
    public ResultBean<Integer> updateScore(String teacherid, SelectCourse selectCourse) {
        String courseid = teacherBo.queryTeachCourse(teacherid).getCourseid();
        selectCourse.setSelectcourseid(courseid);
        return new ResultBean<>(sscb.updateScore(selectCourse));
    }

    @PutMapping("")
    public ResultBean<Integer> updateTeacher(Teacher teacher) {
        return new ResultBean<>(teacherBo.updateTeacher(teacher));
    }

    @GetMapping("/notice")
    public ResultBean<List<Notice>> queryNotice() {
        NoticeQuery noticeQuery = new NoticeQuery();
        noticeQuery.setLimit(100);
        return new ResultBean<>(noticeBo.getNotices(noticeQuery));
    }

    @GetMapping("/course/{teacherid}")
    public ResultBean<Course> queryCourse(@PathVariable("teacherid") String teacherid) {
        return new ResultBean<>(teacherBo.queryTeachCourse(teacherid));
    }

    @GetMapping("/{teacherid}")
    public ResultBean<List<Student>> queryStudents(@PathVariable("teacherid") String teacherid) {
        String courseid = teacherBo.queryTeachCourse(teacherid).getCourseid();
        return new ResultBean<>(scsb.queryCourseStudents(courseid));
    }

    @GetMapping("/student/{studentid}")
    public ResultBean<Student> queryStudent(@PathVariable("studentid") String studentid) {
        return new ResultBean<>(studentBo.queryStudentById(studentid));
    }

    @GetMapping("/score/{studentid}")
    public ResultBean<SelectCourse> queryscore(@PathVariable("studentid") String studentid, String teacherid) {
        String courseid = teacherBo.queryTeachCourse(teacherid).getCourseid();
        return new ResultBean<>(sscb.queryScore(studentid, courseid));
    }

    @GetMapping("")
    public ResultBean<Teacher> queryTeacher(String teacherid) {
        return new ResultBean<>(teacherBo.queryTeacherById(teacherid));
    }
}
